<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
<!--    导入自己的css文件-->
    <link rel="stylesheet" href="../css/my-css.css">
</head>
<body>
<div id="app">
    <el-container>
        <my-header></my-header>

        <el-main style="width: 1200px; height: 600px; margin: 0 auto;padding-left: 125px">
            <el-row gutter="20">
                <el-col span="4">
                    <el-card style="height: 500px">
                        <p style="color: #169FE4; margin-bottom: 30px ">个人信息</p>
<!--                        <p @click="location.href='/usermodel/friendlist.html'"  style="margin-bottom: 30px;cursor: pointer">好友列表</p>-->
                        <p style="margin-bottom: 30px;cursor: pointer" @click="location.href='../notemodel/noteManagement.html'" >笔记管理</p>
                        <p style="margin-bottom: 30px;cursor: pointer" @click="location.href='../videomodel/videoManagement.html'">视频管理</p>
                    </el-card>
                </el-col>

                <el-col span="20">
                    <el-card style="height: 550px">
                        <el-form label-width="100px">
                            <el-form-item label="头像">
                                <img :src="user.avatar" style="width: 145px;height: 145px; border-radius: 10px;float: left">
                                <el-upload style="float: left"
                                           action="/v1/upload"
                                           name="file"
                                           limit="1"
                                           list-type="picture-card"
                                           :on-success="handleSuccess"
                                           :on-preview="handlePictureCardPreview"
                                           :on-remove="handleRemove">
                                    <i class="el-icon-plus"></i>
                                </el-upload>
                                <el-dialog :visible.sync="dialogVisible">
                                    <img width="100%" :src="dialogImageUrl" alt="">
                                </el-dialog>
                            </el-form-item>
                            <el-form-item label="用户名" style="margin-top: -20px">
                                <el-input disabled :value="user.username"
                                          style="width: 200px"></el-input>
                            </el-form-item>
                            <el-form-item label="昵称">
                                <el-input placeholder="请输入昵称" v-model="user.nickname" style="width: 200px"></el-input>
                            </el-form-item>
                            <el-form-item label="年龄">
                                <el-input v-model="user.age" style="width: 200px"></el-input>
                            </el-form-item>
                            <el-form-item label="性别">
                                <el-radio-group v-model="user.gender">
                                    <el-radio :label="0">男</el-radio>
                                    <el-radio :label="1">女</el-radio>
                                </el-radio-group>
                            </el-form-item>
                            <el-form-item label="简介">
                                <el-input type="text" placeholder="来一句个人简介吧" v-model="user.intro" style="width: 200px"></el-input>
                            </el-form-item>
                            <el-form-item>
                                <el-button type="primary" @click="save()">保存信息</el-button>
                            </el-form-item>
                        </el-form>
                    </el-card>
                </el-col>
            </el-row>
        </el-main>

        <my-footer></my-footer>
    </el-container>
</div>
</body>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<!--引入axios框架文件-->
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<!--导入自己的头部js文件-->
<script src="../js/my-header.js"></script>
<!--导入自己的尾部js文件-->
<script src="../js/my-footer.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                dialogImageUrl: '',
                dialogVisible:false,
                user:localStorage.user?JSON.parse(localStorage.user):null,
                newAvatar: ''
            }
        },
        methods: {
            handleSuccess(response,file,fileList){//上传成功时调用该方法
                //response==file.response 代表服务器响应的ResultVo
                v.newAvatar = response.data;

            },
            handlePictureCardPreview(file) {
                console.log(file.url)
                this.dialogImageUrl = file.url;
                this.dialogVisible = true;
            },
            handleRemove(file, fileList) {
                //发出删除文件的请求file.response上传成功时服务器响应的内容，即ResultVo
                axios.get("/v1/upload/remove?url="+file.response.data).then(response =>{
                    v.newAvatar="";//删除图片时删除url
                    v.$message.success("成功删除头像")
                })
            },
            save(){
                if (v.newAvatar!=""){
                    v.user.avatar = v.newAvatar;
                }
                console.log(v.user)
                axios.post("/v1/users/update",v.user).then(response=>{
                    if (response.data.code==20000){
                        if (v.newAvatar!=""){
                            v.user.avatar = v.newAvatar;
                        }
                        localStorage.user = JSON.stringify(v.user);
                        v.$message.success("修改信息成功")
                        location.reload();
                    }
                })
            }
        }
    })
</script>
</html>